package com.lx.spring.config.condition;

import com.lx.spring.config.bean.RainBow;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
import org.springframework.core.type.AnnotationMetadata;

public class MyImportBeanDefinitionRegistrar implements ImportBeanDefinitionRegistrar {


    /**
     *
     * @param importingClassMetadata
     * @param registry
     */
    public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
        boolean a = registry.containsBeanDefinition("com.lx.spring.config.bean.Blue");
        boolean b = registry.containsBeanDefinition("com.lx.spring.config.bean.Yellow");
        if(a && b){
            BeanDefinition bd = new RootBeanDefinition(RainBow.class);
            registry.registerBeanDefinition("rainBow", bd);
        }
    }
}
